package com.yzr.work;

import com.rabbitmq.client.*;
import com.yzr.util.RabbitMqClient;
import org.omg.SendingContext.RunTime;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class Consumer1 {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitMqClient.getConnection();

        final Channel channel = connection.createChannel();
        channel.basicQos(1);
        channel.queueDeclare("work", true, false, false, null);

        channel.basicConsume("work", false, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                try {
                    TimeUnit.MILLISECONDS.sleep(2000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println("消费者-1：" + new String(body));
                channel.basicAck(envelope.getDeliveryTag(), true);
            }
        });

    }
}
